package com.action;

import java.util.ArrayList;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.bean.MessageBean;
import com.bean.RecordBean;
import com.dao.StateQueryDao;
import com.exception.DBException;
import com.exception.StateQueryException;

public class StateQueryAction
{
	StateQueryDao sqd = new StateQueryDao();

	private void State_Barcode(HttpServletRequest request,
			HttpServletResponse response, MessageBean message)
			throws DBException, StateQueryException
	{
		ArrayList<RecordBean> list = sqd.qState_Barcode(message);
		request.setAttribute("state", list);
		request.setAttribute("message", message);
		try
		{
			request.getRequestDispatcher("/lab_admin/stateQuery.jsp").forward(
					request, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}

	}

	private void State_InsName(HttpServletRequest request,
			HttpServletResponse response, MessageBean message)
			throws DBException, StateQueryException
	{
		ArrayList<RecordBean> list = sqd.qState_InsName(message);
		request.setAttribute("state", list);
		request.setAttribute("message", message);
		try
		{
			request.getRequestDispatcher("/lab_admin/stateQuery.jsp").forward(
					request, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	private void State_UserID(HttpServletRequest request,
			HttpServletResponse response, MessageBean message)
			throws DBException, StateQueryException
	{
		ArrayList<RecordBean> list = sqd.qState_UserID(message);
		request.setAttribute("state", list);
		request.setAttribute("message", message);
		try
		{
			request.getRequestDispatcher("/lab_admin/stateQuery.jsp").forward(
					request, response);
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}

	public void getState(HttpServletRequest request,
			HttpServletResponse response, MessageBean message)
			throws DBException, StateQueryException
	{
		if ("insname".equals(message.getKey()))
		{
			this.State_InsName(request, response, message);
			return;
		}
		if ("barcode".equals(message.getKey()))
		{
			this.State_Barcode(request, response, message);
			return;
		}
		if ("userid".equals(message.getKey()))
		{
			this.State_UserID(request, response, message);
			return;
		}
	}
}
